home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / Class_ProgressWindow.cpp < prev    next >
C/C++ Source or Header  |  1995-11-15  |  5KB  |  180 lines

  1. #include "Class_ProgressWindow.h"
  2. #include "QDUtils.h"
  3.  
  4. enum {
  5.     kDefaultReadDelay        = 1,        // 5 ticks
  6.  
  7.     kProgressWindowWidth    = 260,
  8.     kProgressWindowHeight    = 70,
  9.     
  10.     kProgressBarTop            = kProgressWindowHeight - 20,
  11.     kProgressBarHeight        = 13,
  12.     
  13.     kPrimaryStrLeftPos        = 20,
  14.     kPrimaryStrBotPos        = 18,
  15.     kSecondaryStrLeftPos    = kPrimaryStrLeftPos,
  16.     kSecondaryStrBotPos        = kPrimaryStrBotPos + 16,
  17.     
  18.     kProgressWindowBackColor = 56797
  19. };
  20.  
  21. // ---------------------------------------------------------------------------
  22.  
  23. ProgressWindow::ProgressWindow(GDHandle targetMonitor, short maxValue) {
  24.     Rect windowBounds;
  25.  
  26.     this->primaryStr[0] = 0;
  27.     this->secondaryStr[0] = 0;
  28.     this->readDelay = kDefaultReadDelay;
  29.  
  30.     SetRect(&windowBounds, 0, 0, kProgressWindowWidth, kProgressWindowHeight);
  31.     CenterRect(&windowBounds, &(**targetMonitor).gdRect);
  32.     MoveRectTo(&windowBounds, windowBounds.left, 100);
  33.     
  34.     this->progressWindow = NewCWindow(NULL,
  35.         &windowBounds,
  36.         "\p ",
  37.         false,
  38.         altDBoxProc,
  39.         (WindowPtr)-1,
  40.         false,
  41.         0);
  42.     SetPort(this->progressWindow);
  43.  
  44.     FlushRectTopLeft(&windowBounds);
  45.  
  46.     RGBColor backColor;
  47.     // Light gray
  48.     backColor.red = backColor.green = backColor.blue = kProgressWindowBackColor;
  49.     RGBBackColor(&backColor);
  50.  
  51.     RGBColor fillColor, bkgndColor;
  52.     // Dark blue
  53.     fillColor.red = 0;
  54.     fillColor.green = 13107;
  55.     fillColor.blue = 65535;
  56.     // Light blue
  57.     bkgndColor.red = 39321;
  58.     bkgndColor.green = 52428;
  59.     bkgndColor.blue = 65535;
  60.     
  61.     Rect progressRect = windowBounds;
  62.     InsetRect(&progressRect, 20, 0);
  63.     progressRect.top = windowBounds.top + kProgressBarTop;
  64.     progressRect.bottom = progressRect.top + kProgressBarHeight;
  65.     
  66.     this->progressBar = new ProgressBar(&progressRect,
  67.         maxValue, 0, this->progressWindow, &fillColor, &bkgndColor);
  68.     
  69.     ShowWindow(this->progressWindow);
  70.     this->Update();
  71. } // END ctor
  72.  
  73. // ---------------------------------------------------------------------------
  74.  
  75. ProgressWindow::~ProgressWindow() {
  76.     HideWindow(this->progressWindow);
  77.  
  78.     if (this->progressBar != NULL)
  79.         delete(this->progressBar);
  80.     
  81.     DisposeWindow(this->progressWindow);
  82. } // END dtor
  83.  
  84. // ---------------------------------------------------------------------------
  85.  
  86. void ProgressWindow::Update() {
  87.     EraseRect(&this->progressWindow->portRect);
  88.     this->progressBar->Update();
  89.     
  90.     this->DrawPrimaryString();
  91.     this->DrawSecondaryString();
  92. } // END Update
  93.  
  94. // ---------------------------------------------------------------------------
  95.  
  96. void ProgressWindow::DrawPrimaryString() {
  97.     Rect stringRect;
  98.     
  99.     SetRect(&stringRect, kPrimaryStrLeftPos, kPrimaryStrBotPos - 12,
  100.         this->progressWindow->portRect.right, kPrimaryStrBotPos + 4);
  101.     EraseRect(&stringRect);
  102.     MoveTo(kPrimaryStrLeftPos, kPrimaryStrBotPos);
  103.     if (this->primaryStr[0] > 0)
  104.         DrawString(this->primaryStr);
  105. } // END DrawPrimaryString
  106.  
  107. // ---------------------------------------------------------------------------
  108.  
  109. void ProgressWindow::DrawSecondaryString() {
  110.     Rect stringRect;
  111.     
  112.     SetRect(&stringRect, kSecondaryStrLeftPos, kSecondaryStrBotPos - 12,
  113.         this->progressWindow->portRect.right, kSecondaryStrBotPos + 4);
  114.     EraseRect(&stringRect);
  115.     MoveTo(kSecondaryStrLeftPos, kSecondaryStrBotPos);
  116.     if (this->secondaryStr[0] > 0)
  117.         DrawString(this->secondaryStr);
  118. } // END DrawSecondaryString
  119.  
  120. // ---------------------------------------------------------------------------
  121.  
  122. void ProgressWindow::Increment() {
  123.     this->progressBar->Increment();
  124. } // END Increment
  125.  
  126. // ---------------------------------------------------------------------------
  127.  
  128. void ProgressWindow::IncrementBy(short stepValue) {
  129.     this->progressBar->IncrementBy(stepValue);
  130. } // END IncrementBy
  131.  
  132. // ---------------------------------------------------------------------------
  133.  
  134. void ProgressWindow::IncrementTo(short curValue) {
  135.     this->progressBar->IncrementTo(curValue);
  136. } // END IncrementTo
  137.  
  138. // ---------------------------------------------------------------------------
  139.  
  140. void ProgressWindow::SetPrimaryMessage(Str255 message) {
  141.     if (message != NULL) {
  142.         BlockMove(&message[1], &this->primaryStr[1], message[0]);
  143.         this->primaryStr[0] = message[0];
  144.     }
  145.     else
  146.         this->primaryStr[0] = 0;
  147.  
  148.     this->DrawPrimaryString();
  149.  
  150.     if (this->readDelay > 0) {
  151.         long dummy;
  152.         Delay(readDelay, &dummy);
  153.     }
  154. } // END SetPrimaryMessage
  155.  
  156. // ---------------------------------------------------------------------------
  157.  
  158. void ProgressWindow::SetSecondaryMessage(Str255 message) {
  159.     if (message != NULL) {
  160.         BlockMove(&message[1], &this->secondaryStr[1], message[0]);
  161.         this->secondaryStr[0] = message[0];
  162.     }
  163.     else
  164.         this->secondaryStr[0] = 0;
  165.  
  166.     this->DrawSecondaryString();
  167.  
  168.     if (this->readDelay > 0) {
  169.         long dummy;
  170.         Delay(readDelay, &dummy);
  171.     }
  172. } // END SetSecondaryMessage
  173.  
  174. // ---------------------------------------------------------------------------
  175.  
  176. void ProgressWindow::FinishProgress() {
  177.     while (!this->progressBar->IsDone()) {
  178.         this->progressBar->Increment();
  179.     }
  180. } // END FinishProgress